class Solution:
    def removeDuplicates(self, nums):
        if not nums:
            return 0
        return self.helper(nums, 0, len(nums) - 1)

    def helper(self, nums, left, right):
        if left > right:
            return 0
        if left == right:
            return 1
        mid = (left + right) // 2
        left_len = self.helper(nums, left, mid)
        right_len = self.helper(nums, mid + 1, right)

        # 检查左半部分的最后一个元素和右半部分的第一个元素是否相同
        if nums[left + left_len - 1] == nums[mid + 1]:
            # 覆盖右半部分的元素到左半部分末尾
            for i in range(mid + 1, right + 1):
                nums[left + left_len + i - (mid + 1) - 1] = nums[i]
            return left_len + right_len - 1
        else:
            # 直接拼接左右部分
            for i in range(mid + 1, right + 1):
                nums[left + left_len + i - (mid + 1)] = nums[i]
            return left_len + right_len
